//
// afix_deque.h
//

#ifndef _CHLDS_DEQUE_H_
#define _CHLDS_DEQUE_H_

#include "chlds_type.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _TDeque
{
    void*   data;
    sint32  head;
    sint32  tail;
    sint32  used;
    sint32  elen;
    sint32  size;
} TDeque;

sint32 deque_create(TDeque* pDeque, const sint32 elen);

sint32 deque_release(TDeque* pDeque);

sint32 deque_push_head(TDeque* pDeque, const void* p);

sint32 deque_push_tail(TDeque* pDeque, const void* p);

void* deque_pop_head(TDeque* pDeque);

void* deque_pop_tail(TDeque* pDeque);

sint32 deque_used(const TDeque* pDeque);


#define DEQUE_CREATE(_pDeque, _type)            deque_create(_pDeque, sizeof(_type))
#define DEQUE_RELEASE(_pDeque)                  deque_release(_pDeque)
#define DEQUE_PUSH_HEAD(_pDeque, _v)            deque_push_head(_pDeque, &(_v))
#define DEQUE_PUSH_TAIL(_pDeque, _v)            deque_push_tail(_pDeque, &(_v))
#define DEQUE_POP_HEAD(_pDeque, _type)          (*(_type*)deque_pop_head(_pDeque))
#define DEQUE_POP_TAIL(_pDeque, _type)          (*(_type*)deque_pop_tail(_pDeque))
#define DEQUE_USED(_pDeque)                     deque_used(_pDeque)

#ifdef __cplusplus
}
#endif

#endif // _AFIX_DEQUE_H_
